package com.itheima.dao.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.domain.Book;
import com.itheima.service.BookService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/*SpringBoot测试*/
@SpringBootTest
public class BookServiceTestCase {

    /*注入数据层对象*/
    @Autowired
    private BookService bookService;

    /*根据id查询单个数据*/
    @Test/*测试类注解*/
    void testGetById() {
        System.out.println(bookService.getById(4));
    }

    /*新增数据*/
    @Test/*测试类注解*/
    void testSave() {
        Book book = new Book();
        book.setType("书籍类型");
        book.setName("书籍名称");
        book.setDescription("书籍描述");
        bookService.save(book);
    }

    /*删除数据*/
    @Test/*测试类注解*/
    void testUpdate() {
        Book book = new Book();
        book.setId(5);
        book.setType("洒点水");
        book.setName("服务器");
        book.setDescription("去干啥");
        bookService.update(book);
    }

    /*删除数据*/
    @Test/*测试类注解*/
    void testDelete() {
        bookService.delete(6);
    }

    /*查询所有数据*/
    @Test/*测试类注解*/
    void testGetAll() {
        System.out.println(bookService.getAll());
    }

    /*分页查询*/
    @Test/*测试类注解*/
    void testGetPage() {
        IPage<Book> iPage = bookService.getPage(1, 5);
        System.out.println(iPage.getCurrent());/*打印当前页是第几页*/
        System.out.println(iPage.getSize());/*打印每一页显示多少条数据*/
        System.out.println(iPage.getTotal());/*打印一共有多少条数据*/
        System.out.println(iPage.getPages());/*打印一共有几页*/
        System.out.println(iPage.getRecords());/*总记录数据*/
    }

}
